package mine.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.orm.SugarRecord;
import com.whu.administrator.ws.R;
import com.whu.administrator.ws.UIHandler;

import model.NoteBook;
import utils.TimeUtil;

/**
 * 记录
 * Created by Administrator on 2016/3/19.
 */
public class NoteTheThingActivity extends UIHandler.BaseActivity {

    EditText et_title;
    EditText et_content;
    Button btn_commit;

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v == btn_commit)
            {
                commit();
            }
        }
    };

    private void commit() {
        if (et_title.getText().toString().isEmpty())
        {
            Toast.makeText(this,"标题不能为空",Toast.LENGTH_SHORT).show();
            return;
        }

        if (et_content.getText().toString().isEmpty())
        {
            Toast.makeText(this,"内容不能为空",Toast.LENGTH_SHORT).show();
            return;
        }

        NoteBook noteBook = new NoteBook(TimeUtil.currentTime(),et_title.getText().toString(),et_content.getText().toString());
        SugarRecord.save(noteBook);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notethething);
        initview();
    }

    // 初始化界面
    private void initview() {
        btn_commit = (Button) findViewById(R.id.id_btn_commit);
        btn_commit.setOnClickListener(onClickListener);
        et_title = (EditText) findViewById(R.id.id_et_title);
        et_content = (EditText) findViewById(R.id.id_et_content);
    }
}
